package com.abel.threadpool;

import java.util.concurrent.*;

/**
 * @author xiachao
 * @date 2019/1/21
 */
public class Demo {
    public static void main(String[] args) {
        ExecutorService executorService = new ThreadPoolExecutor(0, 5, 3, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(5));
        for (int i = 1; i <= 10; i++) {
            executorService.submit(new Task(i));
        }

    }

}
class Task implements Runnable {
    int num;
    public Task(int num){
        this.num = num;
    }
    @Override
    public void run() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("Task "+num+" completed");
    }
}
